package chen.valuebean;
import java.util.ArrayList;
public class Goods 
{
    private ArrayList goodslist=new ArrayList();//用来存储全部商品
    private void init()
    {												//静态代码块
	String[] names={"苹果","香蕉","梨","橘子"};//商品名称
	float[] prices={2.8f,3.1f,2.5f,2.3f};	   //商品价格
        String[] imgnames={"1.jpg","2.jpg","3.jpg","4.jpg"};//商品价格
	for(int i=0;i<4;i++)
        {   //初始化商品信息列表
	    //定义一个GoodsSingle类对象来封装商品信息			
	    GoodsSingle single=new GoodsSingle();
	    single.setName(names[i]); //封装商品名称信息
	    single.setPrice(prices[i]); //封装商品价格信息
	    single.setNum(1); //封装购买数量信息
            single.setImg(imgnames[i]);
	    goodslist.add(i,single); //保存商品到goodslist集合对象中
	}	
  }

    public ArrayList getGoodslist() {
        return goodslist;
    }
    
    public Goods(){ init();}

}




